home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / toolbox / chop < prev    next >
Text File  |  1994-02-21  |  652b  |  26 lines

  1. //
  2. // CHOP    CHOP(X, t) is the matrix obtained by rounding the elements of X
  3. //         to t significant binary places.
  4. //         Default is t=23, corresponding to IEEE single precision.
  5. //
  6.  
  7. chop = function(x, t)
  8. {
  9.   local( c, e, m, n, p, y );
  10.   if(!exist (t)) { t = 23; }
  11.   m = size(x)[1]; n = size(x)[2];
  12.  
  13.   // Use the representation:
  14.   // x[i,j] = 2^e[i,j] * .d[1]d[2]...d[s] * sign(x[i,j])
  15.  
  16.   // On the next line `+(x==0)' avoids passing a zero argument to LOG, which
  17.   // would cause a warning message to be generated.
  18.  
  19.   y = abs(x) + (x == 0);
  20.   e = floor(log(y)./log(2) + 1);
  21.   p = (2.*ones(m,n)).^(t-e);
  22.   c = round(p.*x)./p;
  23.  
  24.   return c;
  25. };
  26.